use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum UserTypeEnum {
    Admin(i8, String),
    Ordinary(i8, String),
    Guest(i8, String),
    Unknown(i8, String),
}

impl UserTypeEnum {
    pub fn get_name(&self) -> &str {
        match self {
            UserTypeEnum::Admin(_, name) => name,
            UserTypeEnum::Ordinary(_, name) => name,
            UserTypeEnum::Guest(_, name) => name,
            UserTypeEnum::Unknown(_, name) => name,
        }
    }
}

impl From<i8> for UserTypeEnum {
    fn from(value: i8) -> Self {
        match value {
            1 => UserTypeEnum::Admin(value, String::from("admin")),
            2 => UserTypeEnum::Ordinary(value, String::from("user")),
            3 => UserTypeEnum::Guest(value, String::from("guest")),
            _ => UserTypeEnum::Unknown(0, String::from("-1")),
        }
    }
}

impl ToString for UserTypeEnum {
    fn to_string(&self) -> String {
        self.get_name().to_owned()
    }
}